#ifndef WXSDIMENSIONPROPERTY_H
#define WXSDIMENSIONPROPERTY_H

#include "../../properties/wxsproperties.h"
#include "../../wxscodinglang.h"
#include "../wxscodercontext.h"

struct wxsDimensionData {
  long Value;
  bool DialogUnits;

  wxsDimensionData(): Value( 0 ), DialogUnits( false ) {}


  inline long GetPixels( wxWindow* Parent ) {
    return DialogUnits ?
           wxDLG_UNIT( Parent, wxSize( Value, 0 ) ).GetWidth() :
           Value;
  }


  inline long GetDialogUnits( wxWindow* Parent ) {
    return !DialogUnits ?
           Parent->ConvertPixelsToDialog( wxSize( Value, 0 ) ).GetWidth() :
           Value;
  }


  wxString GetPixelsCode( wxsCoderContext* Context );

};


class wxsDimensionProperty: public wxsProperty {
  public:


    wxsDimensionProperty(
      const wxString& PGName,
      const wxString& PGDUName,
      const wxString& DataName,
      long Offset,
      long DefaultValue = 0,
      bool DefaultDialogUnits = false,
      int Priority = 100 );


    virtual const wxString GetTypeName() { return _T( "wxsDimension" ); }

  protected:

    virtual void PGCreate( wxsPropertyContainer* Object, wxPropertyGridManager* Grid, wxPGId Parent );
    virtual bool PGRead( wxsPropertyContainer* Object, wxPropertyGridManager* Grid, wxPGId Id, long Index );
    virtual bool PGWrite( wxsPropertyContainer* Object, wxPropertyGridManager* Grid, wxPGId Id, long Index );
    virtual bool XmlRead( wxsPropertyContainer* Object, TiXmlElement* Element );
    virtual bool XmlWrite( wxsPropertyContainer* Object, TiXmlElement* Element );
    virtual bool PropStreamRead( wxsPropertyContainer* Object, wxsPropertyStream* Stream );
    virtual bool PropStreamWrite( wxsPropertyContainer* Object, wxsPropertyStream* Stream );

  private:
    long Offset;
    long DefaultValue;
    bool DefaultDialogUnits;

    wxString PGDUName;
};




#define WXS_DIMENSION(ClassName,VarName,PGName,PGDUName,DataName,Default,DUDefault) \
  { static wxsDimensionProperty _Property(PGName,PGDUName,DataName,wxsOFFSET(ClassName,VarName),Default,DUDefault); \
    Property(_Property); }


#define WXS_DIMENSION_P(ClassName,VarName,PGName,PGDUName,DataName,Default,DUDefault,Priority) \
  { static wxsDimensionProperty _Property(PGName,PGDUName,DataName,wxsOFFSET(ClassName,VarName),Default,DUDefault,Priority); \
    Property(_Property); }



#endif
